package com.example.zhangxin.myhuatuob2b.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.zhangxin.myhuatuob2b.R;

public class SearchActivity extends AppCompatActivity implements View.OnClickListener {

    private ImageView imageBack;
    private EditText editSearch;
    private TextView textSearchButton;
    private ListView searchListView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);
        initView();
    }

    private void initView() {
        imageBack = (ImageView) findViewById(R.id.imageBack);
        editSearch = (EditText) findViewById(R.id.editSearch);
        textSearchButton = (TextView) findViewById(R.id.textSearchButton);
        searchListView = (ListView) findViewById(R.id.searchListView);
        imageBack.setOnClickListener(this);
        textSearchButton.setOnClickListener(this);
    }

    private void submit() {
        // validate
        String keyword = editSearch.getText().toString().trim();
        if (TextUtils.isEmpty(keyword)) {
            Toast.makeText(this, "内容不能为空", Toast.LENGTH_SHORT).show();
            return;
        }else{
            Intent intent = new Intent(SearchActivity.this, GoodsListFragmentManager.class);
            intent.putExtra("keyword", keyword);
            intent.putExtra("gc_name", keyword);
            SearchActivity.this.startActivity(intent);
            SearchActivity.this.finish();
        }

        // TODO validate success, do something


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.imageBack:
                this.finish();
                break;
            case R.id.textSearchButton:
                submit();
                break;
        }
    }
}
